/*
题目描述：对称的二叉树
递归对称比较即可，很简单
 */
public class E28 {
    public static void main(String[] args) {
        TreeNode root = new TreeNode('a');
        root.left = new TreeNode('b');
        root.right = new TreeNode('b');
        root.left.left = new TreeNode('c');
        root.left.right = new TreeNode('d');
        root.right.left = new TreeNode('d');
        root.right.right = new TreeNode('c');

        boolean res = isSymmetrical(root);

        System.out.println(res);


    }

    public static boolean isSymmetrical(TreeNode pRoot){
        if(pRoot == null){
            return true;
        }
        return helper(pRoot, pRoot);
    }

    public static boolean helper(TreeNode root1, TreeNode root2){
        if(root1 == null && root2 == null){
            return true;
        }
        if(root1 == null || root2 == null){
            return false;
        }

        if(root1.value != root2.value){
            return false;
        }
        return helper(root1.left, root2.right) && helper(root1.right, root2.left);
    }
}
